package controller;

import java.util.ArrayList;
import java.util.Observer;

import javax.swing.table.AbstractTableModel;

import model.Absence;
import model.Teacher;

@SuppressWarnings("serial")
public class TableModelAbsence extends AbstractTableModel implements Observer {

	private ArrayList<Absence> list;

	public TableModelAbsence() {
		setList(new ArrayList<Absence>(Teacher.getInstance().getAllAbsences()));

	}

	// Set number of columns
	public int getColumnCount() {

		return 6;
	}

	// Set number of rows
	public int getRowCount() {
		int count = Teacher.getInstance().getAllAbsences().size();
		return count;
	}

	// Fill the rows with all the groups
	public Object getValueAt(int row, int col) {

		ArrayList<Absence> list = new ArrayList<Absence>(Teacher.getInstance()
				.getAllAbsences().descendingSet());
		switch (col) {
		case 0:
			return list.get(row).getAbsence_Teacher();
		case 1:
			return list.get(row).getAbsence_Substitude();
		case 2:
			return list.get(row).getAbsence_Hours();
		case 3:
			return list.get(row).getAbsence_StartDate();
		case 4:
			return list.get(row).getAbsence_EndDate();
		case 5:
			return list.get(row).getAbsence_Id();

		}
		return null;
	}

	// Set column names
	public String getColumnName(int column) {
		switch (column) {
		case 0:
			return "Uitvaller";
		case 1:
			return "Invaller";
		case 2:
			return "Uren";
		case 3:
			return "Begin";
		case 4:
			return "Eind";
		}
		return null;
	}

	public ArrayList<Absence> getList() {
		return list;
	}

	public void setList(ArrayList<Absence> list) {
		this.list = list;
	}

	@Override
	public void update(java.util.Observable o, Object arg) {
		// TODO Auto-generated method stub

	}

}
